/**
 * 
 */
package org.lex.utils.collections;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * @author Daniel Liu
 * 
 */
public class SingleElementIterator<T> implements Iterator<T> {
	private final T element;
	private boolean hasNext = false;

	public SingleElementIterator(T element) {
		this.element = element;
		if (null != element)
			hasNext = true;
	}

	public boolean hasNext() {
		return hasNext;
	}

	public T next() {
		if (true == hasNext) {
			hasNext = false;
			return element;
		} else {
			throw new NoSuchElementException();
		}
	}

	public void remove() throws UnsupportedOperationException {
		throw new UnsupportedOperationException("not supported");
	}
}
